package com.roc.web.action.merinfo;

import java.util.ArrayList;
import java.util.List;

import com.roc.page.BaseSearchCondition;
import com.roc.page.WhereHQLFieldBean;
import com.roc.util.Constance;
import com.roc.util.constant.MerinfoStatus;
import com.roc.util.constant.Role;

public class MerinfoChangeCheckSearchCondition extends BaseSearchCondition{

	private String orgCode ;//所属机构
	private String merchantNo;//商户号
	private String merchantName;//商户名称
	private String  merBrName; //营业名称
	private String cardNo;  //法人身份证
	private String dealCode;//变更类型
	//private String status; 
	private String opId;    //操作员id
	private String roleId; //角色
    private int changeFlag;//待领件状态
    private  String rkopId;//风控操作员
	
	@Override
	protected List<WhereHQLFieldBean> getWhereHQLFieldBeanList() {
		// TODO Auto-generated method stub
		    List<WhereHQLFieldBean> filedBeanList = new ArrayList<WhereHQLFieldBean>();
		    
		    if(changeFlag==2){ //领件查询（待审核查询）
				if(roleId.equals(Role.RISK_CONTROL_OPERATORS.getCode()) || 
				   roleId.equals(Role.RISK_CONTROL_LEAD.getCode())){//风控角色只查询刚进件的
					
					filedBeanList.add(new WhereHQLFieldBean(" TM.STATUS ='W'"));
				}/*else{
					filedBeanList.add(new WhereHQLFieldBean(" TM.STATUS IN('"+MerinfoStatus.S_1.getCode()+"','"+MerinfoStatus.S_4.getCode()+"','"+MerinfoStatus.S_5.getCode()+"')"));
				}*/
			} 
			if(changeFlag==4){ //审核查询
				filedBeanList.add(new WhereHQLFieldBean(" TM.STATUS = 'L' "));
				filedBeanList.add(new WhereHQLFieldBean(" TM.MID IN (SELECT TC.MERNO FROM T_CHANGE_RECEIVE TC WHERE TC.OP_ID ="+rkopId.trim()+" AND TC.STATUS='0')"));
			}
		   
		
		    if(Constance.isNotEmpty(orgCode)&&!"99".equals(orgCode)){//所属机构
				filedBeanList.add(new WhereHQLFieldBean("A.BANK_BELONG_CD", orgCode.trim(), "=", false));
			}
		   
		    if(Constance.isNotEmpty(dealCode)&&!"99".equals(dealCode)){ //商户信息变更类型
				filedBeanList.add(new WhereHQLFieldBean("TM.DEAL_CODE", dealCode.trim(), "=", false));
			}
		    if(Constance.isNotEmpty(merchantNo)){ //商户号
				filedBeanList.add(new WhereHQLFieldBean("TM.MID", merchantNo.trim(), "=", false));
			}
			
			if(Constance.isNotEmpty(cardNo)){ //法人身份证号
				filedBeanList.add(new WhereHQLFieldBean("A.CERTIF_NO", cardNo.trim(), "=", false));
			}
			if(Constance.isNotEmpty(merchantName)){ //商户名称 （模糊）
				filedBeanList.add(new WhereHQLFieldBean("A.NAME", merchantName.trim(), "like", false,"ALL"));
			}
			if(Constance.isNotEmpty(merBrName)){ //营业名称 （模糊）
				filedBeanList.add(new WhereHQLFieldBean("A.NAME_BUSI", merBrName.trim(), "like", false,"ALL"));
			}
		
			return filedBeanList;
		
			
		
	}

	@Override
	protected String getRowCountHQL() {
    	        StringBuffer  sb= new StringBuffer();
    	        sb.append(" SELECT COUNT(1)");
                sb.append(" FROM T_MERINFO_CHANGE TM");
                sb.append(" LEFT JOIN  TBL_INS_INF  C  ON  TM.MID = C.INS_ID_CD");
                sb.append(" LEFT JOIN  TBL_MCHT_BANKACCOUNT D ON TM.MID = D.OWNER_CD");
                
                sb.append(" LEFT JOIN  TBL_MCHT_INF A ON A.MCHT_CD = TM.MID");  
                sb.append(" WHERE 1=1 AND TM.DEAL_CODE IS NOT NULL  ");
                return sb.toString();
	}

	@Override
	protected String getSearchHQL() {
    	        StringBuffer  sb= new StringBuffer();
	        sb.append(" SELECT    TM.MID,TM.DEAL_CODE,A.NAME_BUSI,A.NAME MERNAME,A .STATUS,A.CONTACT_NAME,");
	        sb.append(" A.CONTACT_PHONENO,A.CERTIF,A.CERTIF_NO, ");
	        sb.append("D.NAME accountname,D.ACCOUNT,A .REG_ADDR,TM.DT_CREATE_TIME,");
	        sb.append(" CASE '1000' WHEN (SELECT DISTINCT PROD_CD FROM TBL_MCHT_BIZ_DEAL y WHERE y.MCHT_CD = A .MCHT_CD AND y.PROD_CD = '1000') THEN 'T1' ELSE '0' END  T1_type, ");
	        sb.append(" CASE '1171' WHEN (SELECT DISTINCT PROD_CD FROM TBL_MCHT_BIZ_DEAL y WHERE y.MCHT_CD = A .MCHT_CD AND y.PROD_CD = '1171') THEN 'T0' ELSE '0' END  T0_type, ");
	        sb.append(" TM.id");
	        sb.append(" FROM T_MERINFO_CHANGE TM");
            sb.append(" LEFT JOIN  TBL_INS_INF  C  ON  TM.MID = C.INS_ID_CD");
            sb.append(" LEFT JOIN  TBL_MCHT_BANKACCOUNT D ON TM.MID = D.OWNER_CD");   
	        
	        sb.append(" LEFT JOIN  TBL_MCHT_INF A ON A.MCHT_CD = TM.MID");
	        sb.append("  WHERE 1=1 AND TM.DEAL_CODE IS NOT NULL ");
	       
	        return sb.toString();
	}

	@Override
        protected String getOrderPartOfHQL() {
                return " ORDER BY TM.DT_CREATE_TIME ASC  ";
        }

	

	public String getMerchantNo() {
		return merchantNo;
	}

	public void setMerchantNo(String merchantNo) {
		this.merchantNo = merchantNo;
	}

	public String getMerchantName() {
		return merchantName;
	}

	public void setMerchantName(String merchantName) {
		this.merchantName = merchantName;
	}

	public String getMerBrName() {
		return merBrName;
	}

	public void setMerBrName(String merBrName) {
		this.merBrName = merBrName;
	}

	

	public String getCardNo() {
		return cardNo;
	}

	public void setCardNo(String cardNo) {
		this.cardNo = cardNo;
	}



	public String getDealCode() {
		return dealCode;
	}

	public void setDealCode(String dealCode) {
		this.dealCode = dealCode;
	}

	public String getOrgCode() {
		return orgCode;
	}

	public void setOrgCode(String orgCode) {
		this.orgCode = orgCode;
	}

	

	public String getOpId() {
		return opId;
	}

	public void setOpId(String opId) {
		this.opId = opId;
	}

	public String getRoleId() {
		return roleId;
	}

	public void setRoleId(String roleId) {
		this.roleId = roleId;
	}

	public int getChangeFlag() {
		return changeFlag;
	}

	public void setChangeFlag(int changeFlag) {
		this.changeFlag = changeFlag;
	}

	public String getRkopId() {
		return rkopId;
	}

	public void setRkopId(String rkopId) {
		this.rkopId = rkopId;
	}


	
	

}
